#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date    : 2016-11-22 10:37:47
# @Author  : Your Name (you@example.org)
# @Link    : http://example.org
# @Version : $Id$

from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
from config import config

db = SQLAlchemy()

def create_app(config_name):
    app = Flask(__name__)
    app.config.from_object(config[config_name])
    config[config_name].init_app(app)

    # 初始化插件
    db.init_app(app)

    # 注册蓝本
    from .main import main as main_blueprint
    from .vmctl import vmctl as vmctl_blueprint
    app.register_blueprint(main_blueprint, url_prefix='/')
    app.register_blueprint(vmctl_blueprint, url_prefix='/vmctl')

    return app